package cate.game.play.skill.passive.furniture;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.passive.PassiveHandler;
import easy.java.struct.ref.DoubleRef;

/**
 * 受到伤害的35%在2回合内以【持续受伤】的方式扣除，处于此状态下不会重复触发；击杀任意单位后清除【持续受伤】状态，并恢复自身15%最大生命值
 */
public class 持续受伤PH extends PassiveHandler {

	private double 伤害系数;

	private int 回合数;

	private double 击杀恢复;

	//伤害系数=3500&回合数=2&击杀恢复=1500
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		伤害系数 = args.getWDouble("伤害系数", 0d);
		回合数 = args.getInt("回合数", 1);
		击杀恢复 = args.getWDouble("击杀恢复", 0d);
	}


	private int settleRound;

	private Fighter recordActor;

	private double ignDamage;

	@Override
	public void adjustSkillDamage(ActionCtx action, Fighter actor, int reason, DoubleRef doubleRef) {
		if (settleRound > 0) {
			return;
		}
		settleRound = action.getRound().index;
		recordActor = actor;
		ignDamage = doubleRef.v * 伤害系数;
		doubleRef.v -= ignDamage;
	}

	@Override
	public void onRoundEnd(ActionCtx action) {
		if (settleRound > 0) {
			if (ignDamage > 0 && 回合数 > 0) {
				skill.owner.attr.buffHurt(action, recordActor, ignDamage / 回合数);
			}
			if (settleRound + 回合数 - 1 >= action.getRound().index) {
				clearBuff();
			}
		}
	}

	@Override
	public void onKill(ActionCtx action, Fighter target) {
		skill.owner.attr.passiveHeal(action, skill.owner.attr.total().hpTotal() * 击杀恢复);
		clearBuff();
	}

	private void clearBuff(){
		settleRound = 0;
		recordActor = null;
		ignDamage = 0;
	}
}
